﻿// JScript 文件

//mod
var mb = new devmb("zview");

var col = 0;
var row = 0;
var _t = 0;
var _time = 0;

//标志位，标志是否已提取了端子状态
var bcdshow = false;
var battshow = false;
var cdlist = [];

//var bshowdzzt = false;
var bshowfmb = false;

var startcol;
//var bfirstdotimer = false;

var devcol;

function onLoad(maj, min, no, bm)
{
    //top.Loading()
    
    if ((maj == 1 && min == 86) || (maj == 1 && min == 85))
    {
        var mbbutton = document.getElementById("mbbutton");
        mbbutton.disabled = "disabled";
    }
        
    //ajax请求
    var url = "/main.ashx";
    var data = "_method=DjsbMb&Major="+maj+"&Minor="+min+"&No="+no+"&Bm="+bm;
    CtnTrans.Ajax(url,"post",data, initDevmb, null,{loading:true,loadingText:"系统查询中，请稍候..."});
    //CtnDlg.loading("系统查询中，请稍候...");

}

function initDevmb(devxml)
{
    var XmlDoc = CtnXML.getXmlDoc();
    if (XmlDoc != null)
    {
        XmlDoc.loadXML(devxml.responseText);
        var nodes = XmlDoc.selectNodes('DEVINFO');
        if(nodes.length == 0)
        {
            return;
        }
        else
        {
            var vdevtype = nodes[0].getAttribute("DEVTYPE");
            var vdevmajor = nodes[0].getAttribute("DEVMAJ");
            var vdevminor = nodes[0].getAttribute("DEVMIN");
            var vdevno = nodes[0].getAttribute("DEVNO");
            var vdevbm = nodes[0].getAttribute("DEVBM");

            mb.devtype = parseInt(vdevtype);
            mb.devmajor = parseInt(vdevmajor);
            mb.devminor = parseInt(vdevminor);
            mb.devno = parseInt(vdevno);
            mb.devbm = vdevbm;
            
            var zcolnum = nodes[0].getAttribute("ZCOLNUM");
            var zmodnum = nodes[0].getAttribute("ZMODNUM");
            var zstartcolno = nodes[0].getAttribute("ZSTARTCOL");
            var zendcolno = nodes[0].getAttribute("ZENDCOL");
            var fcolnum = nodes[0].getAttribute("FCOLNUM");
            var fmodnum = nodes[0].getAttribute("FMODNUM");
            var fstartcolno = nodes[0].getAttribute("FSTARTCOL");
            var fendcolno = nodes[0].getAttribute("FENDCOL");
            
            if(zcolnum == 0) return;
            
            mb.setDevSpec(parseInt(zcolnum), parseInt(zmodnum), parseInt(zstartcolno), parseInt(zendcolno), parseInt(fcolnum), parseInt(fmodnum), parseInt(fstartcolno), parseInt(fendcolno));
            
            var modlist = new Array();
            //var cdlist = new Array();
            //var collist = new Array();
            var nodes1 = nodes[0].selectNodes('MODINFO');
            if(nodes1.length == 0)
            {
                return;
            }
            else
            {
                var vmods = nodes1[0].selectNodes("MOD");
                
                for (var i = 0; i < vmods.length; i++)
                {
                    var modinfo = new devmod("");
                    
                    modinfo.EntityNo = parseInt(vmods[i].getAttribute("MODNO"));
                    modinfo.DevBm = vmods[i].getAttribute("MODDEVBM");
                    modinfo.devNo = mb.devno;
                    modinfo.devtype = parseInt(vmods[i].getAttribute("MODDEVTYPE"));
                    modinfo.ColNo = parseInt(vmods[i].getAttribute("MODCOLNO"));
                    modinfo.BlockNo = parseInt(vmods[i].getAttribute("MODBLOCKNO"));
                    modinfo.StartPortNo = parseInt(vmods[i].getAttribute("MODSTARTPORT"));
                    modinfo.RowNum = parseInt(vmods[i].getAttribute("MODROWNUM"));
                    modinfo.ColNum = parseInt(vmods[i].getAttribute("MODCOLNUM"));
                    modinfo.RowColOrd = parseInt(vmods[i].getAttribute("RCORD"));
                    modinfo.UpDownOrd = parseInt(vmods[i].getAttribute("UDORD"));
                    modinfo.LeftRightOrd = parseInt(vmods[i].getAttribute("LRORD"));
                    
                    modlist.push(modinfo);
                }
            }
            
            var nodes2 = nodes[0].selectNodes('CDINFO');
            if(nodes2.length == 0)
            {
                return;
            }
            else
            {
                var vcds = nodes2[0].selectNodes("CD");
                for (var i = 0; i < vcds.length; i++)
                {
                    var cdinfo = new cditem();
                    
                    cdinfo.entityno = parseInt(vcds[i].getAttribute("CDNO"));
	                cdinfo.devbm = vcds[i].getAttribute("CDDEVID");
	                //cdinfo.devNo = 
	                cdinfo.devtype = parseInt(vcds[i].getAttribute("CDDEVTYPE"));
	                cdinfo.colno = parseInt(vcds[i].getAttribute("CDCOLNO"));
	                cdinfo.startport = parseInt(vcds[i].getAttribute("CDSTARTPORT"));
	                cdinfo.endport = parseInt(vcds[i].getAttribute("CDENDPORT"));
	                cdinfo.cblno = vcds[i].getAttribute("CDCBLBM");
	                cdinfo.cblbm = vcds[i].getAttribute("CDCBLNO");
	                cdinfo.cbltype = parseInt(vcds[i].getAttribute("CDCBLTYPE"));
	                cdinfo.startcblord = parseInt(vcds[i].getAttribute("CDSTARTCBLORD"));
	                cdinfo.endcblord = parseInt(vcds[i].getAttribute("CDENDCBLORD"));
                    cdinfo.cdfx = parseInt(vcds[i].getAttribute("CDFX"));
                    
                    cdlist.push(cdinfo);
                }
            }

            mb.setViewMbRange(10, 20, 2000, 2000);

            mb.setModlist(modlist, /*collist,*/ cdlist);
            CtnDlg.unloading();
            mb.disp();
            

            selectcolno();

            var title = document.getElementById("title");
            
            var str = "";
            switch(mb.devtype)
            {
            case 1:
                str = "配线架";
                break;
            case 2:
                str = "交接箱";
                break;
            case 3:
                str = "分线盒";
                break;
            }
            
            title.innerHTML = "<strong>" + str + " " + mb.devbm + "</strong>";
        }
    }
}

//选择列号
function selectcolno()
{
    if (mb.devtype == 1)
    {
        top.CtnDlg.prompt("选择要查看的端子列号",1,dispMdfMb,22);
//        var url = "../PntManager/UseInfoOfCol.htm";
//        top.CtnDlg.open(url, 
//                       {
//                            title : "选择要查看的端子列号",
//                            width : 400,
//                            height : 150,
//                            srcwin : window,
//                            data : 
//                            {
//                                action : "disp"
//                            } 
//                       }
//                       );
//        var vcol = window.showModalDialog(url,"","dialogWidth:400px;dialogHeight:150px;dialogLeft:350px;dialogtop:280px");
//        dispMdfMb(vcol);
        
    }
    else
    {
        startcol = 0;
        col = 0;
        row = 0;
        _t = setTimeout("DoTimer()", 100);
    }
}

function dispMdfMb(vcol,yyy)
{
    if (vcol == null)
        {
            return;
        }
        
        col = parseInt(vcol);
        
        if (mb.zcolnum != 0 && col >= mb.zstartcolno && col <= mb.zendcolno)
        {
            startcol = col - mb.zstartcolno;
            col = startcol;
            row = 0;
            _t = setTimeout("DoTimer()", 100); 
        }
        else
        {
            if ((mb.zcolnum == 0) || (mb.fcolnum == 0))
            {
                top.CtnDlg.msg("此面无列!");
            }
            else
            {
                top.CtnDlg.msg("输入列号错误!");
            }
            return;
        }
}


function showCdList(cdlist)
{
    var strHtml = "";
    
    strHtml += "<center><table bordercolor='darkgray' border=1><tr><td>";
    strHtml += "<table border=1>";
    strHtml += "<tr style='background-color:white'>";
    strHtml += "<td><strong>";
    strHtml += "设备编码";
    strHtml += "</strong></td>";
    if (cdlist.length && cdlist[0].devtype == enumEBOX_MDF)
    {
        strHtml += "<td><strong>";
        strHtml += "列号";
        strHtml += "</strong></td>";
    }
    strHtml += "<td><strong>";
    strHtml += "起始端子";
    strHtml += "</strong></td>";
    strHtml += "<td><strong>";
    strHtml += "终止端子";
    strHtml += "</strong></td>";
    strHtml += "<td><strong>";
    strHtml += "电缆编码";
    strHtml += "</strong></td>";
    strHtml += "<td><strong>";
    strHtml += "起始线序";
    strHtml += "</strong></td>";
    strHtml += "<td><strong>";
    strHtml += "终止线序";
    strHtml += "</strong></td>";
    strHtml += "</tr>";
    for (var i = 0; i < cdlist.length; i++)
    {
        strHtml += "<tr>";
        strHtml += "<td>";
        //strHtml += cdlist[i].devbm;
        strHtml += mb.devbm;
        strHtml += "</td>";
        if (cdlist[i].devtype == enumEBOX_MDF)
        {
            strHtml += "<td>";
            strHtml += cdlist[i].colno;
            strHtml += "</td>";
        }
        strHtml += "<td>";
        strHtml += cdlist[i].startport;
        strHtml += "</td>";
        strHtml += "<td>";
        strHtml += cdlist[i].endport;
        strHtml += "</td>";
        strHtml += "<td>";
        strHtml += cdlist[i].cblno;
        strHtml += "</td>";
        strHtml += "<td>";
        strHtml += cdlist[i].startcblord;
        strHtml += "</td>";
        strHtml += "<td>";
        strHtml += cdlist[i].endcblord;
        strHtml += "</td>";
        strHtml += "</tr>";
    }
    strHtml += "</table>";
    strHtml += "</td></tr></table></center>";
    
    var cdview = document.getElementById("cdview");
    cdview.innerHTML = strHtml;
}

function showAtt(major, minor, entno)
{
    var url="../Dialog/Att.aspx?major="+major+"&minor="+minor+"&id="+entno+"&action=view";

    var att = document.getElementById("att");
    att.src = url;
    //att.innerHTML = "<iframe name='attfrm' height=100% width=100% src=\"" + url + "\" style=\"visibility:hidden\"></iframe>"
}

function showView(typ)
{
    var att = document.getElementById("att");
    var cdview = document.getElementById("cdview");
    var mbzview = document.getElementById("zview");
    var mbfview = document.getElementById("fview");
    var cutline = document.getElementById("cutline");
    
    cdview.style.visibility = "hidden";
    mbzview.style.visibility = "hidden";
    mbfview.style.visibility = "hidden";
    att.style.visibility = "hidden";
    cutline.style.visibility = "hidden";
    $("jumpview").style.visibility = "hidden";
    //att.children[0].style.visibility = "hidden";    
    switch (typ)
    {
    case 0:
        if (!battshow)
        {
            showAtt(mb.devmajor, mb.devminor, mb.devno);
            battshow = true;
        }
        att.style.visibility = "visible";
        $("att").show();
//        att.style.height = document.body.clientHeight - 20;
        //document.frames("hello").document.
        //att.children[0].style.visibility = "visible";
    break;
    case 1:
        if (!bcdshow)
        {
            showCdList(cdlist);            
            bcdshow = true;
        }
        cdview.style.visibility = "visible";
        $("cdview").show();
    break;
    case 2:
        if (mb.face)
        {
            mbzview.style.visibility = "visible";
            $("zview").show();
            mbfview.style.visibility = "hidden";
        }
        else
        {
            mbfview.style.visibility = "visible";
            $("fview").show();
            mbzview.style.visibility = "hidden";
        }
        
//        if(bshowdzzt)
//        {
        cutline.style.visibility = "visible";
        $("cutline").show();
//        }
    break;
    }
}

function showMb(button)
{
//    bshowdzzt = false;
//    var cutline = document.getElementById("cutline");
//    cutline.style.visibility = "hidden";
    
    var mbzview = document.getElementById("zview");
    var mbfview = document.getElementById("fview");
    
    mb.face = !mb.face;
    
    if (mb.face)
    {
        button.value = "反面";
    }
    else
    {
        button.value = "正面";
    }
    
    if (!bshowfmb && mb.fcolnum != 0)
    {
        bshowfmb = true;
        mb.div = "fview";
        mb.disp();
        selectcolno();
        mbfview.style.visibility = "visible";
        mbzview.style.visibility = "hidden";
    }
    else
    {
        if (mb.face)
        {
            mbzview.style.visibility = "visible";
            mbfview.style.visibility = "hidden";
        }
        else
        {
            mbfview.style.visibility = "visible";
            mbzview.style.visibility = "hidden";
        } 
    }
//    col = 0;
//    row = 0;
//    _t = setTimeout("DoTimer()", 100);
}

function stopShowDz()
{
    clearTimeout(_t);
    return;
}

function DoTimer()
{
    if (!mb)
    {
        return;
    }
    
    mb.dispAMod(col, row);

    row++;
    if (mb.face)
    {
        if (row >= mb.zmodnum)
        {
            row = 0;
            col++;
        }
        col = col % mb.zcolnum;
    }
    else
    {
        if (row >= mb.fmodnum)
        {
            row = 0;
            col++;
        }
        col = col % mb.fcolnum;
    }
    
    if (startcol == col && row == 0)
    {
        clearTimeout(_t);
        return;
    }
    
    _t = setTimeout("DoTimer()", 100);
}

function showKhzl()
{
    var url="Query/DldCdUseQry.aspx?MajorType=" + mb.devmajor + "&MinorType=" + mb.devminor + "&EntityBm=" + escape(mb.devbm);
    var vt = new top.ctnToolId();
    top.ExecuteATool(vt.ID_DLDCDUSE, url);
}

//查看端子占用状态

function showDzZt()
{    
    var devCol = -1;
    var startPort;
    var endPort;
        
    if (mb.devtype == 1)
    {   
        var url = "PntManager/UseInfoOfCol.htm";
        //var vcol = window.showModalDialog(url,"","dialogWidth:400px;dialogHeight:150px;dialogLeft:350px;dialogtop:280px");
        var devno = mb.devno;
        var devtype = mb.devtype;
        
//        top.CtnDlg.open(url, 
//                       {
//                            title : "选择要查看的端子列号",
//                            width : 400,
//                            height : 150,
//                            srcwin : window,
//                            data : 
//                            {
//                                action : "getdzzt",
//                                devId : devno,
//                                devType : devtype,
//                                startPort : 0,
//                                endPort : 0
//                            } 
//                       }
//                       );
        top.CtnDlg.prompt("选择要查看的端子列号", 1, getDzZt, {devId:devno, type : devtype, stp : 0, edp : 0});
                       

    }
    else
    {
        if(!mb.cdlist) 
        {
            top.CtnDlg.msg("没有成端信息", null, "DzZt");
            return;
        }
        if(mb.cdlist.length == 0) 
        {
            top.CtnDlg.msg("没有成端信息", null, "DzZt");
            return;
        }
        for (var i = 0; i < mb.cdlist.length; i++)
        {
            startPort = mb.cdlist[i].startport;
            endPort = mb.cdlist[i].endport;
            getDzZt(devCol, {devId : mb.devno, type : mb.devtype, stp : startPort, edp : endPort});
        }
    }
}

function getDzZt(devcol, stru)
{    	    
    devId = stru.devId;
    devType = stru.type;
    startPort = stru.stp;
    endPort = stru.edp;
    
    if(mb.devtype == 1)
    {
        if (!devcol)
        {
            return;
        }
       
        if ((devcol >= mb.zstartcolno && devcol <= mb.zendcolno) || (devcol >= mb.fstartcolno && devcol <=mb.fendcolno))
        {// 输入的列数合法    
            startPort = 0;
            endPort = 0;
            //getDzZt(mb.devno, mb.devtype, devcol, startPort, endPort);
            var url = "/main.ashx";
	        var data = "_method=getdzzt&devId=" + devId + "&devType=" + devType + "&startPort=" + startPort + "&endPort=" + endPort + "&dzlh=" + devcol;
	        CtnTrans.Ajax(url,"post", data, getxmllist, null, {loading:true,loadingGroup:'dzzt'}); 
        }
        else
        {
            alert("输入列号错误!");
            return;
        }
    }
    else
    {
	    //var url = "/main.ashx?
	    var url = "/main.ashx";
	    var data = "_method=getdzzt&devId=" + devId + "&devType=" + devType + "&startPort=" + startPort + "&endPort=" + endPort + "&dzlh=" + devcol;
	    CtnTrans.Ajax(url,"post", data, getxmllist, null, {loading:true,loadingGroup:'dzzt'}); 
	    //CtnDlg.loading("查询中，请稍候...");
	}
}

//列表展示端子跳接信息
var list = null;
var glbDevCol;
var glbStru;
function getDzJmpInfo(stru,devcol)
{
    glbDevCol = devcol;
    glbStru = stru;
    
    $("jumpview").style.visibility = "visible";
    $("cdview").hide();
    $("zview").hide();
    $("fview").hide();
    $("att").hide();
    $("cutline").hide();
    
    list = new CtnListCtrl("list");
    list.create("jumpview");
    list.bfill = 1;
    list.onGoPage = Qurey;
    list.goPage(1);
   
}

function Qurey(page)
{
    devId = glbStru.devId;
    devType = glbStru.type;
    startPort = glbStru.stp;
    endPort = glbStru.edp;
    
    if(mb.devtype == 1)            //MDF
    {
        if (!glbDevCol)
        {
            return;
        }
       
        if ((glbDevCol >= mb.zstartcolno && glbDevCol <= mb.zendcolno) || (glbDevCol >= mb.fstartcolno && glbDevCol <=mb.fendcolno))
        {// 输入的列数合法    
            var url = "/main.ashx";
	        var data = "_method=GetDzJmpInfo&devId=" + devId + "&devType=" + devType + "&startPort=" + startPort + "&endPort=" + endPort + "&dzlh=" + glbDevCol;
	        CtnTrans.Ajax(url,"post", data, listDzZtInfo, null, {loading:true}); 
        }
        else
        {
            alert("输入列号错误!");
            return;
        }
    }
    else
    {
	    var url = "/main.ashx";
	    var data = "_method=GetDzJmpInfo&devId=" + devId + "&devType=" + devType + "&startPort=" + startPort + "&endPort=" + endPort + "&dzlh=" + glbDevCol;
	    CtnTrans.Ajax(url,"post", data, listDzZtInfo, null, {loading:true});
	}
}

function listDzZtInfo(response)
{
    var xmlDoc = CtnXML.getXmlDoc();
	xmlDoc.loadXML(response.responseText);
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
        return;
    }
	list.insertNode(CtnXML.getRootNode(xmlDoc), 1);
	list.show();
}

function setDzZt(list)
{
//    if(list == null) return;
//    var cblbm;
//    var cbltype;
//    var startcblord;
//    var endcblord;
//    var listcol = new Array();
//    var listdz = new Array();
//    var liststate = new Array();
//    
//    for (var i = 0; i < mb.cdlist.length; i++)
//    {   
//        if (mb.cdlist[i].devtype == 1 && devcol != mb.cdlist[i].colno)
//        {
//            continue;
//        }
//        
//        cblbm = mb.cdlist[i].cblbm;
//        cbltype = mb.cdlist[i].cbltype;
//        startcblord = mb.cdlist[i].startcblord;
//        endcblord = mb.cdlist[i].endcblord;
//                 
//        if (cblbm == list[0].cblcode)
//        {           
//            var dzno = null;
//                        
//            for (var j = 0; j < list.length; j++)
//            {
//                if (mb.cdlist[i].devtype == 1)
//                {
//                    listcol[listcol.length] = mb.cdlist[i].colno;
//                }
//                
//                dzno = parseInt(mb.cdlist[i].startport) + parseInt(list[j].cblord) - parseInt(mb.cdlist[i].startcblord);
//                                
//                listdz[listdz.length] = dzno + "";
//                liststate[liststate.length] = list[j].portstate;
//            }
//        }

//    }
    //CtnDlg.unloading();
    var listcol = new Array();
    var listdz = new Array();
    var liststate = new Array();
    if(mb.devtype == 1)
    {
        for(var i=0; i<list.length; i++)
        {
            listcol[listcol.length]       = list[i].devCol;
            listdz[listdz.length]         = list[i].dzXH;
            liststate[liststate.length]   = list[i].dzState;
        }
    }
    else
    {
        for(var i=0; i<list.length; i++)
        {
            listdz[listdz.length]         = list[i].dzXH;
            liststate[liststate.length]   = list[i].dzState;
        }
    }
    mb.setPortState(listcol, listdz, liststate);
}

function dispCol(colno)
{
    col = colno;
    row = 0;
    _time = setTimeout("DoTimerColDisp()", 100); 
//    mb.dispColumn(colno);
}

function DoTimerColDisp()
{
    if (!mb)
    {
        return;
    }
    
    mb.dispAMod(col, row);

    row++;
    if (mb.face)
    {
        if (row >= mb.zmodnum)
        {
            clearTimeout(_time);
            return;
        }
    }
    else
    {
        if (row >= mb.fmodnum)
        {
            clearTimeout(_time);
            return;
        }
    }
    
    _time = setTimeout("DoTimerColDisp()", 100);
}


function getXmlHttp()
{
	var obj = null ;
	try
	{
		obj = new ActiveXObject("Msxml2.XMLHTTP") ;
		return obj ;
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP") ;
			return obj ;
		}
		catch(o)
		{
			obj = null ;
		}
	}
	return null ;
}

//解析xml
function getxmllist(text)
{
    var list = new Array();

	var XmlVal = null;
	try
	{
		XmlVal = new ActiveXObject("Msxml2.DOMDocument.4.0") ;
	}
	catch(e)
	{
		try
		{
			XmlVal = new ActiveXObject("Microsoft.XMLDOM") ;
		}
		catch(o)
		{
			XmlVal = null ;
		}
	}
	
	if (XmlVal == null)
	{ 
	    return
	}
	
	XmlVal.loadXML(text.responseText);
	var node = XmlVal.selectNodes("ROOT");
	
	if(node.length == 0)
	{
		alert("无相关数据！");
		return null;
	}
	else
	{
	    var nodes = node[0].selectNodes("DZINFO");
		for(i = 0; i < nodes.length; i++)
		{
//	      var item = new cblportinfo();
//	      item.cblcode = nodes[i].getAttribute("CblCode");
//	      item.cblord = nodes[i].getAttribute("CblOrd"); 
//	      item.portstate = parseInt(nodes[i].getAttribute("PortState"));
//	      item.TelNum = nodes[i].getAttribute("TelNum");
          var item = new dzInfo();
          item.devId   = nodes[i].getAttribute("DEVID");
	      item.devType = nodes[i].getAttribute("DevType");
	      item.devCol  = nodes[i].getAttribute("DevCol");
	      item.dzXH    = nodes[i].getAttribute("DZXH"); 
	      item.dzState = parseInt(nodes[i].getAttribute("DZSTATE"));
	      
	      list.push(item);
		}
		//return list;    //返回html字符串（通过div显示）
        setDzZt(list)
	}
}

function cblportinfo()
{
    this.cblcode = "";              //	电缆编码
    this.cblord = 0;			    //  电缆线序
    this.telnum = "";		        //  电话号码
    this.portstate = 0;             //  状态

}

function dzInfo()
{
    this.devId = "";
    this.devType = 0;
    this.devCol = -1;
    this.dzXH = 0;
    this.dzState = 0;
}